<?php

use yii\db\Migration;

class m180326_091418_create_orders_count extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->createTable('{{%orders_count}}',[
                'id' => $this->primaryKey()->notNull().' COMMENT \'自增id\'',
                'mechanic_id' => $this->integer()->defaultValue(0)->comment('机构id'),
                'orders_id' => $this->integer()->defaultValue(0)->comment('订单id '),
                'orders_items_id' => $this->integer()->defaultValue(0)->comment('订单详情id'),
                'goods_id' => $this->integer(11)->defaultValue(0)->comment('商品id'),
                'customer_id' => $this->integer()->defaultValue(0)->comment('用户id'),
                'student_id' => $this->smallInteger()->defaultValue(0)->comment('学生id'),
                'mechanic_name' => $this->string(50)->defaultValue(0)->comment('机构名称'),
                'goods_name' => $this->string(50)->defaultValue(0)->comment('课程名称'),
                'customer_name' => $this->string(50)->defaultValue(0)->comment('用户姓名'),
                'student_name' => $this->string(50)->defaultValue(0)->comment('学生姓名'),
                'class_time' => $this->smallInteger()->defaultValue(0)->comment('上课时间'),
                'mobile' => $this->integer()->defaultValue(0)->comment('联系方式'),
                'actual_cash_money' => $this->decimal(10,2)->defaultValue(0)->comment('最终使用金额'),
                'actual_scholarship_money' => $this->decimal(10,2)->defaultValue(0)->comment('最终使用奖学金'),
                'status' => $this->smallInteger()->defaultValue(0)->comment('订单状态 0 预约 1 续费'),
                'created_at' => $this->integer()->defaultValue(0)->comment('下单时间'),
            ]);
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->dropTable('{{%orders_count}}');
        }
    }
}
